package com.example.ribbon.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: zhangtong
 * @Date: 2018/9/11 下午2:48
 */
@RestController
public class ConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")
    @GetMapping(value = "/hello")
    public String hiService() {
        return restTemplate.getForObject("http://HELLO-SERVICE/hello", String.class);
    }

    public String hiError() {
        return "sorry,error!";
    }
}
